<?php
namespace Home\Controller;
use Think\Controller;

class RegController extends Controller{
    
    function index(){
        
        $this -> display();
    }
    //检验注册信息
    function uajax(){
    	//创建用户模型
			$user = D('mvp_user');
			//获取用户名
			
			$name=$_POST['username'];
		
			$user->create();

			$num = $user->where('username='."'".$name."'")->find();
			
			
			//判断用户名是否存在
			if(empty($num)){
				echo 1;
			}else{
				echo 0;
			}
    }
    function pajax(){
    	//创建用户模型
			$user = D('mvp_info');
			//获取用户名
			
			$phone=$_POST['phone'];
		
			$user->create();

			$num = $user->where('phone='."'".$phone."'")->find();
			
			
			//判断用户名是否存在
			if(empty($num)){
				echo 1;
			}else{
				echo 0;
			}
    }
    function checkReg(){
    		$vcode = I('post.vcode');
    		if(!check_verify($vcode)){
    			$this->error('验证码输入错误','',3);
    		}
    		//创建用户模型
			$user = D('mvp_user');
			//获取用户名
		
			$username=trim($_POST['username']);
			$pwd=md5(trim($_POST['pwd']));
			$user->username=$username;
			$user->password=$pwd;
			$_POST['pic'] = '/Public/Home/images/s_img4.jpg';
			$_POST['password'] = $pwd;
			// var_dump($_POST);
			$user->create();
			
			$uid = $user->add();
			//echo $user->_sql();die;
			//var_dump($con);
			$userinfo = M('mvp_info');
			$_POST['uid'] = $uid;
			// var_dump($_POST);
			if(!$userinfo->create()){
			//获取错误信息
				$info = $userinfo->getError();
				$this->error($info,'',3);
			}
			$con = $userinfo->add();
			// echo $userinfo->_sql();
			if($con>0){
			
				$this->success('注册成功！',U('Index/index'),3);	
				session('id',$uid);
				session('name',$username);
							
			}else{
				$this->error('注册失败！请您正确填写！',U('Index/index'),3);
			}
    	}
    }
    	

